package com.aiit.datamanager.service;

import com.aiit.datamanager.dao.EmployeeMapper;
import com.aiit.datamanager.dao.LoginTicketMapper;
import com.aiit.datamanager.entity.Employee;
import com.aiit.datamanager.utils.DataManagerStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 *
 */
@Service
public class EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private LoginTicketMapper loginTicketMapper;

    @Value("${datamanager.path.domain}")
    private String domain;
    @Value("${server.servlet.context-path}")//项目路径
    private String contextPath;

    public Employee findEmployeeById(int employeeId){
        return employeeMapper.selectById(employeeId);
    }

    // 创建新用户
    public Map<String, Object> register(Employee employee){
        Map<String, Object> map = new HashMap<>();

        if(employee == null){
            throw new IllegalArgumentException("参数不能为空");
        }
        if(StringUtils.isBlank(employee.getEmployeeName())){
            map.put("usernameMessage", "账号名不能为空");
            return map;
        }
        if(StringUtils.isBlank(employee.getPassword())){
            map.put("passwordMessage", "密码不能为空");
            return map;
        }
        if(StringUtils.isBlank(employee.getPhoneNumber())){
            map.put("phoneNameMessage", "电话号码不能为空");
            return map;
        }
        Employee temp1 = employeeMapper.selectById(employee.getEmployeeId());
        if(temp1 != null){
            map.put("usernameMessage", "该工号已存在");
            return map;
        }
        // 测试阶段先使用明文存储
        // employee.setPassword(DataManagerStringUtils.md5(employee.getPassword()));
        employee.setCreateTime(new Date());
        employeeMapper.insertEmployee(employee);

        return map;
    }



    public Map<String, Object> login(String userName, String password, int expiredSeconds){


        return null;
    }





}
